#ifndef __EVENTLOOPTHREADPOOL_H__
#define __EVENTLOOPTHREADPOOL_H__

#include "Spark/Net/EventLoopThread.h"
#include <vector>
#include <memory>

class EventLoopThreadPool : public NonCopyable
{
  public:
    EventLoopThreadPool();

    EventLoopThreadPool(EventLoop* base,
                        std::string name = "EventLoopThreadPool");

    ~EventLoopThreadPool();

    void setThreadNum(int threadNums)
    {
        threadNums_ = threadNums;
    }

    void start();

    void wait();

    const std::string& name() const
    {
        return name_;
    }

    size_t size()
    {
        return vThreads_.size();
    }

    EventLoop* getNextLoop();

    EventLoop* getLoop(size_t id);

    std::vector<EventLoop*> getAllLoops() const;

  private:
    EventLoop* baseLoop_;
    const std::string name_;
    bool poolStart_{false};
    int threadNums_{0};
    std::vector<std::unique_ptr<EventLoopThread>> vThreads_;
    std::vector<EventLoop*> loops_;
    size_t loopIndex_;
};

#endif  // __EVENTLOOPTHREADPOOL_H__